package com.ruoyi;

import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

@Configuration
public class FlywayConfig {

    @Autowired
    private DataSource dataSource ;
    @Value("${spring.flyway.baseline-on-migrate}")
    private boolean baselineOnMigrate ;
    @Value("${spring.flyway.locations}")
    private String locations ;
    @Value("${spring.flyway.baseline-version}")
    private String baselineVersion ;
    @Value("${spring.flyway.clean-disabled}")
    private boolean cleanDisabled ;

    @PostConstruct
    public void config(){
        Flyway flyway = Flyway.configure()
                .dataSource(dataSource)
                .baselineOnMigrate(baselineOnMigrate)
                .locations(locations)
                .baselineVersion(baselineVersion)
                .cleanDisabled(cleanDisabled)
                .load();

        flyway.migrate() ;
    }
}
